import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login/login.vue'
import Index from '../views/index/index.vue'
import Product from '../views/Commodity/Product.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'login',
    component: ()=> import("../views/Login/login.vue")
  },
  {
    path: '/index',
    name: 'index',
    component: Index
  },
  {
    path: '/Product',
    name: 'Product',
    component: Product
  },
  {
    path: '/ProduGroup',
    name: 'ProduGroup',
    component: ()=> import("../views/Commodity/ProduGroup.vue")
  },
  {
    path: '/Branding',
    name: 'Branding',
    component: ()=> import("../views/Commodity/Branding.vue")
  },
  {
    path: '/Classification',
    name: 'Classification',
    component: ()=> import("../views/Commodity/Classification.vue")
  },
  {
    path: '/Setup',
    name: 'Setup',
    component: ()=> import("../views/Commodity/Setup.vue")
  },
  // 订单管理
  {
    path: '/OrderOverview',
    name: 'OrderOverview',
    component: ()=> import("../views/Orderman/OrderOverview.vue")
  },
  {
    path: '/Rights',
    name: 'Rights',
    component: ()=> import("../views/Orderman/Rights.vue")
  },
  {
    path: '/Status',
    name: 'Status',
    component: ()=> import("../views/Orderman/Status.vue")
  },
  {
    path: '/Tool',
    name: 'Tool',
    component: ()=> import("../views/Orderman/Tool.vue")
  },
  // 财务管理
  {
    path: '/Balancedetails',
    name: 'Balancedetails',
    component: ()=> import("../views/financialman/Balancedetails.vue")
  },
  {
    path: '/PointsDetails',
    name: 'PointsDetails',
    component: ()=> import("../views/financialman/PointsDetails.vue")
  },
  {
    path: '/Recharge',
    name: 'Recharge',
    component: ()=> import("../views/financialman/Recharge.vue")
  },
  {
    path: '/Statement',
    name: 'Statement',
    component: ()=> import("../views/financialman/Statement.vue")
  },
  // 优惠管理
  {
    path: '/Basicfunction',
    name: 'Basicfunction',
    component: ()=> import("../views/Preferential/Basicfunction.vue")
  },
  {
    path: '/Coupon',
    name: 'Coupon',
    component: ()=> import("../views/Preferential/Coupon.vue")
  },
  // 会员管理
  {
    path: '/GroupSettings',
    name: 'GroupSettings',
    component: ()=> import("../views/Member/GroupSettings.vue")
  },
  {
    path: '/MemberList',
    name: 'MemberList',
    component: ()=> import("../views/Member/MemberList.vue")
  },
  {
    path: '/MemberOverview',
    name: 'MemberOverview',
    component: ()=> import("../views/Member/MemberOverview.vue")
  },
  {
    path: '/Membershiplevel',
    name: 'Membershiplevel',
    component: ()=> import("../views/Member/Membershiplevel.vue")
  },
  // 活动管理
  {
    path: '/FlashKill',
    name: 'FlashKill',
    component: ()=> import("../views/Eventman/FlashKill.vue")
  },
  {
    path: '/Teamwork',
    name: 'Teamwork',
    component: ()=> import("../views/Eventman/Teamwork.vue")
  },
  // 积分管理
  {
    path: '/Classification',
    name: 'Classification',
    component: ()=> import("../views/PointsMall/Classification.vue")
  },
  {
    path: '/Productlist',
    name: 'Productlist',
    component: ()=> import("../views/PointsMall/Productlist.vue")
  },
  {
    path: '/RotationChart',
    name: 'RotationChart',
    component: ()=> import("../views/PointsMall/RotationChart.vue")
  },
  {
    path: '/Statemanag',
    name: 'Statemanag',
    component: ()=> import("../views/PointsMall/Statemanag.vue")
  },
  // 权限管理
  {
    path: '/Administrator',
    name: 'Administrator',
    component: ()=> import("../views/Rights/Administrator.vue")
  },
  {
    path: '/Roles',
    name: 'Roles',
    component: ()=> import("../views/Rights/Roles.vue")
  },
  {
    path: '/Store',
    name: 'Store',
    component: ()=> import("../views/Rights/Store.vue")
  },
  {
    path: '/Withdrawal',
    name: 'Withdrawal',
    component: ()=> import("../views/Rights/Withdrawal.vue")
  },
  // 评价管理
  {
    path: '/Evaluation',
    name: 'Evaluation',
    component: ()=> import("../views/Evaluation/Evaluation.vue")
  },
  // 信息管理
  {
    path: '/Applying',
    name: 'Applying',
    component: ()=> import("../views/Information/Applying.vue")
  },
  {
    path: '/Feedback',
    name: 'Feedback',
    component: ()=> import("../views/Information/Feedback.vue")
  },
  {
    path: '/Medication',
    name: 'Medication',
    component: ()=> import("../views/Information/Medication.vue")
  },
]


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  const token = localStorage.getItem('token')
  if (token!=null) {
    if(to.path !== '/login'){
      next()
    }
  }else{
    if(to.path === '/login'){
      next()
    }else{
      next('/login')
    }
  }
  next()
})

export default router
